//
//  PhotoCollectionView.m
//  HWSGW
//
//  Created by avachen on 15/11/6.
//  Copyright © 2015年 luxuanrui. All rights reserved.
//

#import "PhotoCollectionView.h"
#import "PhotoCell.h"

@implementation PhotoCollectionView{
    NSString *identify;
    
}

- (instancetype)initWithFrame:(CGRect)frame
{
    //创建布局对象
    UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
    //设置滑动方向
    flowLayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    flowLayout.minimumLineSpacing = NO;
    
    //设置布局对象的尺寸
    flowLayout.itemSize = CGSizeMake(kScreenWidth, kScreenHeight);

    self = [super initWithFrame:frame collectionViewLayout:flowLayout];
    
    if (self) {
        
        self.dataSource = self;
        self.delegate = self;
        //注册单元格
        identify = @"PhotoCell";
        [self registerClass:[PhotoCell class] forCellWithReuseIdentifier:identify];
    }
    return self;
}
#pragma mark - UICollectionView delegate
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return self.urls.count;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    //创建子类化单元格返回u
    PhotoCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:identify forIndexPath:indexPath];
//    cell.backgroundColor = [UIColor grayColor];
    //传递数据
    cell.url = self.urls[indexPath.item];
    return cell;
}
- (void)collectionView:(UICollectionView *)collectionView
  didEndDisplayingCell:(UICollectionViewCell *)cell
    forItemAtIndexPath:(NSIndexPath *)indexPath
{
    PhotoCell *pCell = (PhotoCell *)cell;
    [pCell.scrollView setZoomScale:1 animated:NO];
    
}
@end
